﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RightClickExtension.Properties;

namespace RightClickExtension
{
    public partial class frmExist : Form
    {
        #region Instance fields

        private bool _existFile;
        private string _targetFileName;

        #endregion

        #region Instance properties

        /// <summary>
        /// Gets or sets the name of the target file.
        /// </summary>
        /// <value>The name of the target file.</value>
        public string TargetFileName
        {
            get { return _targetFileName; }
            set { _targetFileName = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [exist file].
        /// </summary>
        /// <value><c>true</c> if [exist file]; otherwise, <c>false</c>.</value>
        public bool ExistFile
        {
            get { return _existFile; }
            set { _existFile = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="frmExist"/> is result.
        /// </summary>
        /// <value><c>true</c> if result; otherwise, <c>false</c>.</value>
        public bool Result { get;private set; }

        #endregion

        #region .ctors

        public frmExist()
        {
            InitializeComponent();
        }
        #endregion

        #region Auxiliary methods

        private void btnYes_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbExsitItemName.Text))
            {
                if (_existFile)
                {
                    if (tbExsitItemName.Text.Trim() == _targetFileName)
                        epInput.SetError(tbExsitItemName, Resources.strMessageChangeFileName);
                    else
                    {
                        _targetFileName = tbExsitItemName.Text.Trim();
                        Result = true;
                        Close();
                    }
                }
                else
                {
                    Result = true;
                    Close();
                }
            }
            else
                epInput.SetError(btnYes, Resources.ErrorEmpty);

        }

        private void btnNo_Click(object sender, EventArgs e)
        {
            Result = false;
            Close();
        }

        private void frmExist_Load(object sender, EventArgs e)
        {
            if (_existFile)
            {
                lblMessage.Text = string.Format(Resources.strExsitFile, _targetFileName,Environment.NewLine);
                tbExsitItemName.Text = _targetFileName;
            }
            else
            {
                lblMessage.Text = string.Format(Resources.strNonExistFolder, _targetFileName,Environment.NewLine);
                tbExsitItemName.Text = _targetFileName;
                tbExsitItemName.Enabled = false;
            }
        }

        #endregion
    }
}
